﻿//-----------------------------------------------------------------------
// <copyright file="ServiceCollectionExtensions.cs" company="SLWY Enterprises">
// * Copyright (C) 2017 四川商旅无忧科技有限公司 版权所有。
// * version : 1.0
// * author  : qinchaoyue
// * FileName: ServiceCollectionExtensions.cs
// * history : created by qinchaoyue 2017-10-19 11:14:12
// </copyright>
//-----------------------------------------------------------------------
using System.IO;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.PlatformAbstractions;

using Swashbuckle.AspNetCore.Swagger;

namespace Slwy.Swagger
{
    /// <summary>
    /// 用于快速在前台创建 Swagger
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 注册 swagger 服务并设置
        /// </summary>
        /// <param name="services"> 服务集合 </param>
        public static void AddSwaggerService(this IServiceCollection services)
        {
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(
                    "v1",
                    new Info
                    {
                        Title = "slwy",
                        Version = "v1",
                        Description = "api文档管理器",
                        TermsOfService = "None",
                        Contact = new Contact
                        {
                            Name = "slwy",
                            Email = "shanglv@shanglv.com"
                        }
                    });
                var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "WebApplication.xml");
                c.IncludeXmlComments(filePath);
                c.CustomSchemaIds(type => type.FullName);
            });
        }
    }
}